package com.fanchuan.uzx.ui.utils;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.os.Build;
import android.widget.ListView;

public class ListViewUtils {
	@SuppressLint("NewApi")
	@TargetApi(Build.VERSION_CODES.FROYO)
	public static void scrollToFirst(ListView listView) {
		int p = 1;
		if (android.os.Build.VERSION.SDK_INT >= 11) {
			listView.smoothScrollToPositionFromTop(p, 0);
		} else if (android.os.Build.VERSION.SDK_INT >= 8) {
			int firstVisible = listView.getFirstVisiblePosition();
			int lastVisible = listView.getLastVisiblePosition();
			if (p < firstVisible)
				listView.smoothScrollToPosition(p);
			else
				listView.smoothScrollToPosition(p + lastVisible - firstVisible
						- 2);
		} else {
			listView.setSelectionFromTop(p, 0);
		}
	}
}
